package com.kede.api.order.controller;

import com.alibaba.fastjson.JSON;
import com.kede.api.order.utils.LogisOrderAPiUtils;
import com.kede.domain.LeescoreAddressDomain;
import com.kede.pojo.ResHttp;
import com.kede.service.LeescoreAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单服务
 *
 * @author 11856
 * @date 2023/06/12
 */
@RestController
@RequestMapping("order")
@Slf4j
public class UtileController {


    /**
     * 获取快递信息
     * @param cpCode
     * @param no
     * @return
     */
    @GetMapping("getLogisInfo")
    public ResHttp getLogisInfo(String cpCode, String no){
        return ResHttp.okData(JSON.parse(LogisOrderAPiUtils.getLogisInfo(cpCode,no)));
    }


    @Resource
    private LeescoreAddressService leescoreAddressService;

    /**
     * 获取收货地址
     * @return
     */
    @GetMapping("getLogiAddr")
    public ResHttp getLogiAddr(Integer id){
        LeescoreAddressDomain byId = leescoreAddressService.getById(id);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(byId.getRegion());
        stringBuilder.append(byId.getCity());
        stringBuilder.append(byId.getXian());
        stringBuilder.append(byId.getAddress());

        Map<String,String> map = new HashMap<>();
        map.put("addr",stringBuilder.toString());
        map.put("username",byId.getFirstname());
        return ResHttp.okData(map);
    }



}
